package com.example.demo.common;

import lombok.Getter;

import static com.example.demo.common.CodeMessageEnum.COMMON_PARAM_ERROR;
import static com.example.demo.common.CodeMessageEnum.SYSTEM_ERROR;

/**
 * @author JiJunpeng
 * @date 2018/7/25
 */
@Getter
public class DemoException extends RuntimeException {
    private final CodeMessageEnum codeMessage;

    public DemoException(CodeMessageEnum codeMessage) {
        super(codeMessage.getMessage());
        this.codeMessage = codeMessage;
    }

    public DemoException(String message, CodeMessageEnum codeMessage) {
        super(message);
        this.codeMessage = codeMessage;
    }

    public DemoException(String message, Throwable cause, CodeMessageEnum codeMessage) {
        super(message, cause);
        this.codeMessage = codeMessage;
    }

    public DemoException(Throwable cause, CodeMessageEnum codeMessage) {
        super(codeMessage.getMessage(), cause);
        this.codeMessage = codeMessage;
    }

    public DemoException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, CodeMessageEnum codeMessage) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.codeMessage = codeMessage;
    }

    public static DemoException commonParamException() {
        return new DemoException(COMMON_PARAM_ERROR);
    }

    public static DemoException systemErrorException(){
        return new DemoException(SYSTEM_ERROR);
    }
}
